﻿import { writeFile } from 'fs/promises';


function headFileContent(className: string): string {
        return `#ifndef ${className.toUpperCase()}_H
#define ${className.toUpperCase()}_H

class ${className}
{

public:
    explicit ${className}();
    ~${className}();

private:

};
#endif // ${className.toUpperCase()}_H`;
}


function sourceFileContent(className: string): string {
    return `#include "${className.toLowerCase()}.h"

${className}::${className}()
{
}

${className}::~${className}()
{

}
`;
}

export async function newHeadFile(fileName: string, className: string): Promise<boolean> {
    try {
        // 调用 writeFile 方法异步写入文件
        await writeFile(fileName, headFileContent(className), 'utf8');
        return true;
    } catch (error) {
        console.error('异步创建文件时出错:', error);
    }
    return false;
}

export async function newSourceFile(fileName: string, className: string): Promise<boolean> {
    try {
        // 调用 writeFile 方法异步写入文件
        await writeFile(fileName, sourceFileContent(className), 'utf8');
        return true;
    } catch (error) {
        console.error('异步创建文件时出错:', error);
    }
    return false;
}

